(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "maishu-ui-toolkit", "common"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const ui = require("maishu-ui-toolkit");
    const common_1 = require("common");
    const loadingClassName = 'loading';
    function errorHandle(err, app) {
        if (app == null) {
            app = window[common_1.USER_APP];
        }
        if (err.name == "601") {
            if (this.showLoginPage) {
                return;
            }
            this.showLoginPage = true;
            console.assert(app != null);
            var currentPage = app.currentPage;
            app.showPage('user/login', { return: currentPage.url });
            // setTimeout(() => {
            this.showLoginPage = false;
            //     currentPage.close();
            // }, 800);
            return;
        }
        // let loadingElement = this.element.querySelector(`.${loadingClassName}`) as HTMLElement;
        // if (loadingElement) {
        //     this.renderError();
        // }
        // else {
        // alert(err.message);
        ui.alert({ title: '错误', message: err.message });
        // console.log(err);
        // }
    }
    exports.errorHandle = errorHandle;
});
